<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <button @click="msg.obj.name='rose'">按钮</button>
        <p>{{msg}}</p>
    </div>
    <script src="./vue.js"></script>
    <script>
        new Vue({
            el: "#app",
            data() {
                return {
                    msg: {
                        name: 'jack',
                        age: 16,
                        obj: {
                            name: 'james',
                            age: 11
                        }
                    }
                }
            },
            methods: {

            },
            watch: {
                msg: {
                    // 开启深度侦听
                    deep: true,
                    // 如果任何一个属性改变了都会调用handler
                    handler() {
                        // 里面写想做的事
                        console.log('msg改变了');
                        this.msg.name = 18
                    }
                }
            }
        })
    </script>
</body>

</html>